import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home/'
import Setup from '../views/setup/'
import Caveat from '../views/caveat/'
import History from '../views/history/'
import Adddevice from '../views/addDevice/';
import Login from '../views/login/';
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Login',
    component: Login
  },
  {
    path: '/home',
    name: 'Home',
    component: Home
  },
  {
    path: '/setup',
    name: 'Setup',
    component: Setup
  },
  {
    path: '/caveat',
    name: 'Caveat',
    component: Caveat
  },
  {
    path: '/history',
    name: 'History',
    component: History
  },
  {
    path: '/adddevice',
    name: 'Adddevice',
    component: Adddevice
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

//全局前置守卫
// router.beforeEach((to, from, next) => {
//   if (to.name === 'Login') {
//     axios({
//       url: '/token',
//       method: 'get',
//       headers: {'token': localStorage.getItem('token')}
//     }).then(res => {
//       console.log(res)
//       if (res.data.code === 200) {
//         next('/home')
//       } else {
//         next()
//       }
//     })
//   } else {
//     next()
//   }
// })

export default router
